
package com.example.demo.controller;



import com.example.demo.controller.param.OrderParams;
import com.example.demo.controller.vo.OrderDetailVo;
import com.example.demo.entity.OrderPO;
import com.example.demo.service.OrderService;
import com.example.demo.util.AjaxResult;
import com.google.gson.internal.$Gson$Preconditions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/course")
@CrossOrigin
@ResponseBody
@Api("订单相关接口")
public class OrderConcroller {

    @Autowired
    private OrderService orderService;

    @ApiOperation("获取订单详情")
    @GetMapping("/getOrderDetail")
    public AjaxResult getOrderDetail(@RequestParam("userId")String userId,
                                     @RequestParam("orderId")long orderId){
        OrderPO orderDetailVo = orderService.getOrderDetailVo(userId,orderId);
        return new AjaxResult().ok(orderDetailVo);
    }

    @ApiOperation("获取订单列表")
    @GetMapping("/getOrderList")
    public AjaxResult getOrderList(@RequestParam("userId")@ApiParam("用户ID") String userId,
                                   @RequestParam("statue")@ApiParam("状态：1：全部，2：待成团，3：已成团，4：拼团失败") int status){
        List<OrderPO> list = new ArrayList<>();
        if(status == 1){
            list = orderService.getOrderList(userId);
        }else {
           list  = orderService.getOrderList(userId,status);
        }
        return new AjaxResult().ok(list);
    }

    @ApiOperation("购买")
    @PostMapping("/addOrder")
    public AjaxResult addOrder(@RequestBody OrderParams orderParams){
        String userId = orderParams.getUserId();
        long courseId = orderParams.getCourseId();
        return orderService.addOrder(userId,courseId);
    }

//    @ApiOperation("课程账户")
//    @PostMapping("/RedisTemplate")
//    public RedisTemplate redisTemplate(@RequestParam long courseId){
//        return redisTemplate(courseId);
//    }
}
